home *** CD-ROM | disk | FTP | other *** search
/ Programming Languages Suite / ProgramD2.iso / Borland / Borland C++ V5.02 / SUPERPD.PAK / ABOUTBOX.CPP next >
C/C++ Source or Header  |  1997-05-06  |  6KB  |  237 lines

  1. // aboutbox.cpp : implementation file
  2. //
  3. // This is a part of the Microsoft Foundation Classes C++ library.
  4. // Copyright (C) 1992-1995 Microsoft Corporation
  5. // All rights reserved.
  6. //
  7. // This source code is only intended as a supplement to the
  8. // Microsoft Foundation Classes Reference and related
  9. // electronic documentation provided with the library.
  10. // See these sources for detailed information regarding the
  11. // Microsoft Foundation Classes product.
  12.  
  13.  
  14.  
  15. #include "stdafx.h"
  16. #include "resource.h"
  17. #include "aboutbox.h"
  18. #include <dos.h>
  19. #include <direct.h>
  20.  
  21. #ifdef _DEBUG
  22. #undef THIS_FILE
  23. static char BASED_CODE THIS_FILE[] = __FILE__;
  24. #endif
  25.  
  26. /////////////////////////////////////////////////////////////////////////////
  27. // CAboutBox dialog
  28.  
  29. BEGIN_MESSAGE_MAP(CAboutBox, CDialog)
  30.     //{{AFX_MSG_MAP(CAboutBox)
  31.     //}}AFX_MSG_MAP
  32. END_MESSAGE_MAP()
  33.  
  34. CAboutBox::CAboutBox(CWnd* pParent /*=NULL*/)
  35.     : CDialog(CAboutBox::IDD, pParent)
  36. {
  37.     //{{AFX_DATA_INIT(CAboutBox)
  38.         // NOTE: the ClassWizard will add member initialization here
  39.     //}}AFX_DATA_INIT
  40. }
  41.  
  42. void CAboutBox::DoDataExchange(CDataExchange* pDX)
  43. {
  44.     CDialog::DoDataExchange(pDX);
  45.     //{{AFX_DATA_MAP(CAboutBox)
  46.         // NOTE: the ClassWizard will add DDX and DDV calls here
  47.     //}}AFX_DATA_MAP
  48. }
  49.  
  50. /////////////////////////////////////////////////////////////////////////////
  51. // CAboutBox message handlers
  52.  
  53. BOOL CAboutBox::OnInitDialog()
  54. {
  55.     CDialog::OnInitDialog();
  56.  
  57.     // initialize the big icon control
  58.     m_icon.SubclassDlgItem(IDC_BIGICON, this);
  59.     m_icon.SizeToContent();
  60.  
  61.     #ifndef _MAC
  62.         // fill available memory
  63.         CString str, strFmt;
  64.         strFmt.LoadString(IDS_PHYSICAL_MEM);
  65.  
  66.         MEMORYSTATUS MemStat;
  67.         MemStat.dwLength = sizeof(MEMORYSTATUS);
  68.         GlobalMemoryStatus(&MemStat);
  69.         wsprintf(str.GetBuffer(80), strFmt, MemStat.dwTotalPhys / 1024L);
  70.         str.ReleaseBuffer();
  71.         SetDlgItemText(IDC_PHYSICAL_MEM, str);
  72.  
  73.         // fill disk free information
  74.  
  75. #ifdef __BORLANDC__
  76.         struct diskfree_t diskfree;
  77.       unsigned drive;
  78.       _dos_getdrive(&drive);
  79.         if (_dos_getdiskfree(drive, &diskfree) == 0)
  80. #else
  81.         struct _diskfree_t diskfree;
  82.         if (_getdiskfree(_getdrive(), &diskfree) == 0)
  83. #endif
  84.  
  85.         {
  86.             strFmt.LoadString(IDS_DISK_SPACE);
  87.             wsprintf(str.GetBuffer(80), strFmt,
  88.                 (DWORD)diskfree.avail_clusters *
  89.                 (DWORD)diskfree.sectors_per_cluster *
  90.                 (DWORD)diskfree.bytes_per_sector / (DWORD)1024L);
  91.             str.ReleaseBuffer();
  92.         }
  93.         else
  94.             str.LoadString(IDS_DISK_SPACE_UNAVAIL);
  95.         SetDlgItemText(IDC_DISK_SPACE, str);
  96.     #endif //_MAC
  97.  
  98.     return TRUE;  // return TRUE  unless you set the focus to a control
  99. }
  100.  
  101. /////////////////////////////////////////////////////////////////////////////
  102. // CSplashWnd dialog
  103.  
  104. BEGIN_MESSAGE_MAP(CSplashWnd, CDialog)
  105.     //{{AFX_MSG_MAP(CSplashWnd)
  106.     //}}AFX_MSG_MAP
  107. END_MESSAGE_MAP()
  108.  
  109. void CSplashWnd::DoDataExchange(CDataExchange* pDX)
  110. {
  111.     CDialog::DoDataExchange(pDX);
  112.     //{{AFX_DATA_MAP(CSplashWnd)
  113.         // NOTE: the ClassWizard will add DDX and DDV calls here
  114.     //}}AFX_DATA_MAP
  115. }
  116.  
  117. BOOL CSplashWnd::Create(CWnd* pParent)
  118. {
  119.     //{{AFX_DATA_INIT(CSplashWnd)
  120.         // NOTE: the ClassWizard will add member initialization here
  121.     //}}AFX_DATA_INIT
  122.  
  123.     if (!CDialog::Create(CSplashWnd::IDD, pParent))
  124.     {
  125.         TRACE0("Warning: creation of CSplashWnd dialog failed\n");
  126.         return FALSE;
  127.     }
  128.  
  129.     return TRUE;
  130. }
  131.  
  132. BOOL CSplashWnd::OnInitDialog()
  133. {
  134.     CDialog::OnInitDialog();
  135.     CenterWindow();
  136.  
  137.     // initialize the big icon control
  138.     m_icon.SubclassDlgItem(IDC_BIGICON, this);
  139.     m_icon.SizeToContent();
  140.  
  141.     return TRUE;  // return TRUE  unless you set the focus to a control
  142. }
  143.  
  144. /////////////////////////////////////////////////////////////////////////////
  145. // CSplashWnd message handlers
  146.  
  147. /////////////////////////////////////////////////////////////////////////////
  148. // CBigIcon
  149.  
  150. BEGIN_MESSAGE_MAP(CBigIcon, CButton)
  151.     //{{AFX_MSG_MAP(CBigIcon)
  152.     ON_WM_DRAWITEM()
  153.     ON_WM_ERASEBKGND()
  154.     //}}AFX_MSG_MAP
  155. END_MESSAGE_MAP()
  156.  
  157. /////////////////////////////////////////////////////////////////////////////
  158. // CBigIcon message handlers
  159.  
  160. #define CY_SHADOW   4
  161. #define CX_SHADOW   4
  162.  
  163. void CBigIcon::SizeToContent()
  164. {
  165.     // get system icon size
  166.     int cxIcon = ::GetSystemMetrics(SM_CXICON);
  167.     int cyIcon = ::GetSystemMetrics(SM_CYICON);
  168.  
  169.     // a big icon should be twice the size of an icon + shadows
  170.     SetWindowPos(NULL, 0, 0, cxIcon*2 + CX_SHADOW + 4, cyIcon*2 + CY_SHADOW + 4,
  171.         SWP_NOACTIVATE|SWP_NOMOVE|SWP_NOZORDER);
  172. }
  173.  
  174. void CBigIcon::DrawItem(LPDRAWITEMSTRUCT lpDrawItemStruct)
  175. {
  176.     CDC* pDC = CDC::FromHandle(lpDrawItemStruct->hDC);
  177.     ASSERT(pDC != NULL);
  178.  
  179.     CRect rect;
  180.     GetClientRect(rect);
  181.     int cxClient = rect.Width();
  182.     int cyClient = rect.Height();
  183.  
  184.     // load icon
  185.     HICON hicon = AfxGetApp()->LoadIcon(IDR_MAINFRAME);
  186.     if (hicon == NULL)
  187.         return;
  188.  
  189.     // draw icon into off-screen bitmap
  190.     int cxIcon = ::GetSystemMetrics(SM_CXICON);
  191.     int cyIcon = ::GetSystemMetrics(SM_CYICON);
  192.  
  193.     CBitmap bitmap;
  194.     if (!bitmap.CreateCompatibleBitmap(pDC, cxIcon, cyIcon))
  195.         return;
  196.     CDC dcMem;
  197.     if (!dcMem.CreateCompatibleDC(pDC))
  198.         return;
  199.     CBitmap* pBitmapOld = dcMem.SelectObject(&bitmap);
  200.     if (pBitmapOld == NULL)
  201.         return;
  202.  
  203.     // blt the bits already on the window onto the off-screen bitmap
  204.     dcMem.StretchBlt(0, 0, cxIcon, cyIcon, pDC,
  205.         2, 2, cxClient-CX_SHADOW-4, cyClient-CY_SHADOW-4, SRCCOPY);
  206.  
  207.     // draw the icon on the background
  208.     dcMem.DrawIcon(0, 0, hicon);
  209.  
  210.     // draw border around icon
  211.     CPen pen;
  212.     pen.CreateStockObject(BLACK_PEN);
  213.     CPen* pPenOld = pDC->SelectObject(&pen);
  214.     pDC->Rectangle(0, 0, cxClient-CX_SHADOW, cyClient-CY_SHADOW);
  215.     if (pPenOld)
  216.         pDC->SelectObject(pPenOld);
  217.  
  218.     // draw shadows around icon
  219.     CBrush br;
  220.     br.CreateStockObject(DKGRAY_BRUSH);
  221.     rect.SetRect(cxClient-CX_SHADOW, CY_SHADOW, cxClient, cyClient);
  222.     pDC->FillRect(rect, &br);
  223.     rect.SetRect(CX_SHADOW, cyClient-CY_SHADOW, cxClient, cyClient);
  224.     pDC->FillRect(rect, &br);
  225.  
  226.     // draw the icon contents
  227.     pDC->StretchBlt(2, 2, cxClient-CX_SHADOW-4, cyClient-CY_SHADOW-4,
  228.         &dcMem, 0, 0, cxIcon, cyIcon, SRCCOPY);
  229. }
  230.  
  231. BOOL CBigIcon::OnEraseBkgnd(CDC*)
  232. {
  233.     return TRUE;    // we don't do any erasing...
  234. }
  235.  
  236. /////////////////////////////////////////////////////////////////////////////
  237.